using System;
using System.IO;
using System.Windows.Forms;
using FlexCell;
using Infragistics.Win.UltraWinTabControl;
using PluginFrame;

namespace PcrExperimentProject
{
	public class FormAlleleProjectEditor : FormProjectEditor
	{
		public FormAlleleProjectEditor(IApplication application, IPcrExperimentProject pcrExperimentProject, bool isNewPcrProject, bool isAllowToChangeChannelSettings)
			: base(application, pcrExperimentProject, isNewPcrProject, isAllowToChangeChannelSettings)
		{
			tabPcrProject.Tabs["Melting"].Visible = false;
		}

		protected override void InitializeMeltingSegment()
		{
			grbMeltingSegment.Visible = false;
			chkHRMSegment.Visible = false;
		}

		protected override void InitializeHRMSegment()
		{
			grbHRMSegment.Visible = false;
		}

		protected override void RefreshMeltingSegmentDisplay()
		{
		}

		protected override UltraTabControl IntializeAnalysisOptionTabControl()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			UltraTabControl ultraTabControl = base.IntializeAnalysisOptionTabControl();
			UltraTabControl ultraTabControl2 = ultraTabControl.Tabs[0].TabPage.Controls["Options Tab Control"] as UltraTabControl;
			if (ultraTabControl2.Tabs.Exists(mPcrExperimentProject.Name + " Allele Option"))
			{
				Control control = ultraTabControl2.Tabs[mPcrExperimentProject.Name + " Allele Option"].TabPage.Controls[mPcrExperimentProject.Name + " Allele Option Grid"];
				Grid val = (Grid)(object)((control is Grid) ? control : null);
				val.CellChange += new CellChangeEventHandler(base.analysisOptinGrid_CellChange);
			}
			return ultraTabControl;
		}

		protected override void InitializeProjectRule(bool isLocked)
		{
			tabPcrProject.Tabs["Rule"].Visible = false;
		}

		protected override bool SaveMeltingSegment()
		{
			return true;
		}

		protected override bool SaveProjectRules()
		{
			return true;
		}

		protected override void tabPcrProject_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
		{
			try
			{
				if (e.PreviousSelectedTab != null && e.PreviousSelectedTab.Key.Equals("Analysis Option"))
				{
					UltraTabControl ultraTabControl = pnlAnalysisOption.Controls[0] as UltraTabControl;
					if (ultraTabControl != null)
					{
						mAnalysisService.SaveAnalysisOptionTabControl(ultraTabControl);
					}
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		protected override bool SaveAnalysisOptions()
		{
			UltraTabControl ultraTabControl = pnlAnalysisOption.Controls[0] as UltraTabControl;
			if (ultraTabControl != null)
			{
				string value = mAnalysisService.SaveAnalysisOptionTabControl(ultraTabControl);
				if (!string.IsNullOrEmpty(value))
				{
					MessageBox.Show(value, mResourceManager.GetString("ErrorString"));
					return false;
				}
				return true;
			}
			return false;
		}

		protected override void SaveProject()
		{
			if (mIsNewPcrProject)
			{
				mMenuFile.DropDownItems["SaveAsProjectFile"].PerformClick();
			}
			else
			{
				if (!SaveAnalysisOptions() || !SaveProjectCrossTalk())
				{
					return;
				}
				for (int i = 0; i < tabAmplification.Tabs.Count; i++)
				{
					if (tabAmplification.Tabs[i].Visible && !CheckAmplificationSegment(i))
					{
						return;
					}
				}
				if (mIsSegmentPositionChanged)
				{
					mPcrExperimentProject.PcrProgram.AmplificationSegments = GenerateAmplificationSegements();
				}
				if (CheckProgramFluorescenceDetection())
				{
					if (!mOriginProjectFileName.Equals(mPcrExperimentProject.FileName) && File.Exists(mOriginProjectFileName))
					{
						File.Delete(mOriginProjectFileName);
					}
					mPcrProjectService.SaveExperimentProject(mPcrExperimentProject);
					mOriginProjectFileName = mPcrExperimentProject.FileName;
					mIsNewPcrProject = false;
					mIsSaved = true;
					mIsRefreshSavedFile = true;
				}
			}
		}

		protected override void RefreshAnalysisTabControl(UltraTabControl analysisTabControl, string oldTabName)
		{
			if (analysisTabControl != null)
			{
				analysisTabControl.Tabs[oldTabName + " Basic Option"].Key = mPcrExperimentProject.Name + " Basic Option";
				mAnalysisService.RefreshBasicAnalysisOptionTab(analysisTabControl, mPcrExperimentProject);
				if (analysisTabControl.Tabs.Exists(oldTabName + " Allele Option"))
				{
					analysisTabControl.Tabs[oldTabName + " Allele Option"].Key = mPcrExperimentProject.Name + " Allele Option";
					Control control = analysisTabControl.Tabs[mPcrExperimentProject.Name + " Allele Option"].TabPage.Controls[mPcrExperimentProject.Name + " Allele Option Grid"];
					Grid optionGrid = (Grid)(object)((control is Grid) ? control : null);
					mAnalysisService.RefreshAlleleAnalysisOptionGridContent(mPcrExperimentProject, optionGrid);
				}
			}
		}
	}
}
